<?php

/* @var $this yii\web\View */

use yii\helpers\Html;

$this->title = 'Unicode编码';
$this->params['breadcrumbs'][] = $this->title;

$js = <<<JS
	$('.submit').click(function(){
		var that = $(this);
		var item = that.attr('id');
		var value = $('textarea').val();
		var input = 'item='+item+'&textarea='+value;
		$.post('/utils/do', {input:input}, function(rs){
			if (rs.errno != 0) {
				alert(rs.error);
			}

			if (rs.data.length != 0) {
			    var reg = new RegExp('"', "g");
			    var str = rs.data.replace(reg, '');
				that.parents('li').find('code').empty().text(str);
			}
		},'json');
	});

JS;
$this->registerJs($js);

$css = <<<CSS
    textarea {
        width: 100%;
    }
CSS;
$this->registerCss($css);

?>
<div class="site-index scene">
    <ul>
        <li>
            <p><?= Html::encode($this->title);?> <button id="untoch" class="submit">Unicode转中文</button> <button id="chtoun" class="submit">中文转Unicode</button></p>
            <p><textarea rows="5" placeholder="请把你需要转换的内容粘贴在这里"></textarea></p>
            <p><code></code></p>
        </li>
    </ul>
</div>